package com.zzx.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class DateUtils {

    public static String getFileName(String fileName){
        //获取当前时间
        Date date = new Date();
        // 获取年月日
        String str = "yyyy/MM/dd/";
        DateFormat dateFormat = new SimpleDateFormat(str);
        String format = dateFormat.format(date);
        //生成uuid
        String s = UUID.randomUUID().toString();
        String s1 = s.replaceAll("-", "");
        /*获取文件后缀*/
        int i = fileName.lastIndexOf(".");
        String substring = fileName.substring(i);
//        System.out.println(format);
//        System.out.println(s1+substring);
        StringBuffer buffer = new StringBuffer();
        buffer.append(format);
        buffer.append(s1);
        buffer.append(substring);
        return buffer.toString();
    }

    public static void main(String[] args) {
        DateUtils dateUtils = new DateUtils();
        String 文件 = dateUtils.getFileName("文件.png");
        System.out.println(文件);
    }
}
